package com.gzy.test;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.gzy.BootStart;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Collections;

@SpringBootTest(classes = BootStart.class)
@RunWith(SpringRunner.class)
public class MyTest01 {

    @Test
    public void test1() {
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/week2moni3?useUnicode=true&characterEncoding=UTF8&useSSL=false",
                        "root", "root")
                .globalConfig(builder -> {
                    builder.author("郭梓炀") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .commentDate("yyyy-MM-dd")
                            .outputDir("D://daima/day0503"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.gzy") // 设置父包名
                            .controller("action")
                            // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://daima/day0503")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_center","t_detail","t_goods","t_user","t_ware") // 设置需要生成的表名
                            .addTablePrefix("t_"); // 设置过滤表前缀
                }).strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok().columnNaming(NamingStrategy.no_change)
                    ;

                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
